/*
 *  Class name: AccountDAOImpl.java
 *  Version: 1.0
 *  Date: 22.6.2014
 */

package cz.morosystems.personwebmanager.persistencelayer.daos.impl;

import cz.morosystems.personwebmanager.persistencelayer.daos.AccountDAO;
import cz.morosystems.personwebmanager.persistencelayer.entities.Account;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 *
 * @author Michal Ďuriš
 */
@Repository
public class AccountDAOImpl implements AccountDAO {
    
    @Autowired
    private SessionFactory sessionFactory;

    public AccountDAOImpl() {
    }

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    @Override
    public void changeAccount(Account account) {
        
        sessionFactory.getCurrentSession().merge(account);
    }

    @Override
    public void deleteAccount(Long accountID) {
        
        sessionFactory.getCurrentSession().delete(getAccountByID(accountID));
    }
   
    @Override
    public Account getAccountByID(Long accountID) {
        
        return (Account) sessionFactory.getCurrentSession().get(Account.class, accountID);
    }
    
    

}
